package com.apop.hrss.home.componet;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.apop.common.config.action.Action;
import com.apop.common.mapper.mapper1.OneMapper;
import com.apop.common.util.JsonUtil;
import com.apop.common.util.MapUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Author: zjy
 * Date: 2021/11/9  15:23
 * Describe: 后置处理器 (返回值处理)
 */
@Service
@Slf4j
public class PostProcessor {

    @Autowired
    private OneMapper oneMapper;

    /**
     * 返回的Key转小写
     * @param listMap
     * @param action
     * @return
     */
    public List<Map> keyToLowerCase(List<Map> listMap, Action action){
        return MapUtil.mapListCaseTransfer(listMap,true);
    }
    public List<Map> testMethod2(List<Map> listMap, Action action){
        log.info(" {} ",listMap);
        Map map = new HashMap();
        map.put("ss","123");
        listMap.add(map);
        return listMap;
    }

    /**
     * 108 请求处理
     * @param jsonObject
     * @return
     */
    public JSONObject proc108(JSONObject jsonObject){
        JSONArray row = (JSONArray) jsonObject.get("rows");
        if(row==null){
            return jsonObject;
        }
        JSONArray tree = JsonUtil.listToTree(row,"id","fid","children");
        JSONObject newJsonObj = jsonObject;
        newJsonObj.put("rows",tree);
        return newJsonObj;
    }

    public JSONObject proc117(JSONObject jsonObject){

        return jsonObject;
    }

}
